﻿@using Nop.Admin.Models.ShareBuy;
@model Telerik.Web.Mvc.GridModel<ShareBuyItemModel>
@using Telerik.Web.Mvc.UI

@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-content.png")" alt="" />
        Share Items
    </div>
    <div class="options">
        @*<a href="@Url.Action("Create")" class="t-button">@T("Admin.Common.AddNew")</a>*@
    </div>
</div>
<table class="adminContent">
    <tr>
        <td>
            @(Html.Telerik().Grid<ShareBuyItemModel>()
                    .Name("sharebuyitem-grid")
                    .BindTo(Model.Data)
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Title).Width(150);
                        //columns.Bound(x => x.LanguageName).Width(150);
                        //columns.Bound(x => x.Comments)
                        //    .Width(150)
                        //    .Centered()
                        //    .Template(
                        //    @<div>
                        //            @Html.ActionLink(T("Admin.ContentManagement.News.NewsItems.Fields.Comments").Text + " - " + @item.Comments, "Comments", new { filterByNewsItemId = @item.Id })
                        //        </div>
                         //   )
                         //   .ClientTemplate("<div><a href=\"Comments?filterByNewsItemId=<#= Id #>\">" + T("Admin.ContentManagement.News.NewsItems.Fields.Comments").Text + " - <#= Comments #>" + "</a></div>");
                        //columns.Bound(x => x..Published)
                        //    .Width(100)
                        //    .Template(x => x.Published.ToString().ToLower())
                        //    .Centered();
                        columns.Bound(x => x.CreatedOnUtc)
                            .Width(150)
                            .Centered();
                        columns.Bound(x => x.Id)
                             .Template(@<a onclick="DeleteShare(@item.Id)" href="javascript:void(0);">Delete</a>)
                            //.Template(x => Html.ActionLink("Delete", "Delete", new { id = x.Id }))
                            .ClientTemplate("<a href=\"Delete/<#= Id #>\">Delete</a>")
                            .Width(50)
                            .Centered()
                            .HeaderTemplate("Delete")
                            .Filterable(false);
                    })
                    .Pageable(settings => settings.Total(Model.Total).PageSize(gridPageSize).Position(GridPagerPosition.Both))
                    .DataBinding(dataBinding => dataBinding.Ajax().Select("List", "ShareBuy"))
                    .EnableCustomBinding(true))
        </td>
    </tr>
</table>

<script type="text/javascript">

    function DeleteShare(id)
    {
        if (confirm("Are you sure you want to delete this item?")) {
            $.ajax({
                type:"POST",
                url: "/Admin/ShareBuy/Delete/" + id,
                async: false,
                success: function (data, textStatus) {
                    if (data == "Success") {
                        alert("Delete successfully");
                        location.href = location.href;
                    }
                }
            });
        }
    }
</script>